home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / cursor.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  57KB  |  1,440 lines

  1. /***********************************************************************/
  2. /* CURSOR.C - CURSOR commands                                          */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1995 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Id: cursor.c 2.0 1995/01/26 16:30:29 MH Release MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /***********************************************************************/
  51. #ifdef PROTO
  52. short cursor_cmdline(short col)
  53. #else
  54. short cursor_cmdline(col)
  55. short col;
  56. #endif
  57. /***********************************************************************/
  58. {
  59. /*-------------------------- external data ----------------------------*/
  60.  extern short prefix_width;
  61. /*--------------------------- local data ------------------------------*/
  62.  short rc=RC_OK;
  63. /*--------------------------- processing ------------------------------*/
  64. #ifdef TRACE
  65.  trace_function("cursor.c:  cursor_cmdline");
  66. #endif
  67. /*---------------------------------------------------------------------*/
  68. /* If CMDLINE is OFF return without doing anything.                    */
  69. /*---------------------------------------------------------------------*/
  70.  if (CURRENT_WINDOW_COMMAND == (WINDOW *)NULL)
  71.    {
  72. #ifdef TRACE
  73.     trace_return();
  74. #endif
  75.     return(rc);
  76.    }
  77.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  78.    {
  79.     CURRENT_VIEW->previous_window = CURRENT_VIEW->current_window;
  80.     post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  81.     CURRENT_VIEW->current_window = WINDOW_COMMAND;
  82.    }
  83.  wmove(CURRENT_WINDOW,0,col-1);
  84.  
  85. #ifdef TRACE
  86.  trace_return();
  87. #endif
  88.  return(rc);
  89. }
  90. /***********************************************************************/
  91. #ifdef PROTO
  92. short cursor_down(bool escreen)
  93. #else
  94. short cursor_down(escreen)
  95. bool escreen;
  96. #endif
  97. /***********************************************************************/
  98. {
  99. /*------------------------- external data -----------------------------*/
  100.  extern CHARTYPE CMDARROWSTABCMDx;
  101. /*--------------------------- local data ------------------------------*/
  102.  short rc=RC_OK;
  103. /*--------------------------- processing ------------------------------*/
  104. #ifdef TRACE
  105.  trace_function("cursor.c:  cursor_down");
  106. #endif
  107.  switch(CURRENT_VIEW->current_window)
  108.    {
  109.     case WINDOW_PREFIX:
  110.     case WINDOW_MAIN:
  111.          rc = scroll_line(DIRECTION_FORWARD,1L,FALSE,escreen);
  112.          break;
  113.     case WINDOW_COMMAND:
  114. /*---------------------------------------------------------------------*/
  115. /* Cycle forward  through the command list or tab to first line.       */
  116. /*---------------------------------------------------------------------*/
  117.          if (CMDARROWSTABCMDx)
  118.             rc = Sos_topedge("");
  119.          else
  120.             rc = Retrieve((CHARTYPE *)"+");
  121.          break;
  122.     default:
  123.          display_error(2,(CHARTYPE *)"",FALSE);
  124.          break;
  125.    }
  126. #ifdef TRACE
  127.  trace_return();
  128. #endif
  129.  return(rc);
  130. }
  131. /***********************************************************************/
  132. #ifdef PROTO
  133. short cursor_home(bool save)
  134. #else
  135. short cursor_home(save)
  136. bool save;
  137. #endif
  138. /***********************************************************************/
  139. {
  140. /*-------------------------- external data ----------------------------*/
  141.  extern short prefix_width;
  142. /*--------------------------- local data ------------------------------*/
  143.  CHARTYPE last_win=0;
  144.  unsigned short x=0,y=0;
  145.  short rc=RC_OK;
  146. /*--------------------------- processing ------------------------------*/
  147. #ifdef TRACE
  148.  trace_function("cursor.c:  cursor_home");
  149. #endif
  150. /*---------------------------------------------------------------------*/
  151. /* If CMDLINE is OFF return without doing anything.                    */
  152. /*---------------------------------------------------------------------*/
  153.  if (CURRENT_WINDOW_COMMAND == (WINDOW *)NULL)
  154.    {
  155. #ifdef TRACE
  156.     trace_return();
  157. #endif
  158.     return(rc);
  159.    }
  160.  last_win = CURRENT_VIEW->previous_window;
  161.  CURRENT_VIEW->previous_window =
  162.               CURRENT_VIEW->current_window;
  163.  if (CURRENT_VIEW->current_window != WINDOW_COMMAND)
  164.     {
  165.      post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  166.      CURRENT_VIEW->current_window = WINDOW_COMMAND;
  167.      wmove(CURRENT_WINDOW,0,0);
  168.     }
  169.  else
  170.     {
  171.      if (!line_in_view(CURRENT_VIEW->focus_line))
  172.         CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line;
  173.      pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  174.      if (save)
  175.         CURRENT_VIEW->current_window = last_win;
  176.      else
  177.         CURRENT_VIEW->current_window = WINDOW_MAIN;
  178.      getyx(CURRENT_WINDOW,y,x);
  179.      y = get_row_for_focus_line(CURRENT_VIEW->focus_line,
  180.                                 CURRENT_VIEW->current_row);
  181.      if (CURRENT_VIEW->current_window == WINDOW_PREFIX
  182.      &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT
  183.      &&  prefix_width != PREFIX_WIDTH
  184.      &&  x == 0)
  185.         x = 1;
  186.      wmove(CURRENT_WINDOW,y,x);
  187.     }
  188. #ifdef TRACE
  189.  trace_return();
  190. #endif
  191.  return(rc);
  192. }
  193. /***********************************************************************/
  194. #ifdef PROTO
  195. short cursor_left(bool escreen,bool kedit_defaults)
  196. #else
  197. short cursor_left(escreen,kedit_defaults)
  198. bool escreen,kedit_defaults;
  199. #endif
  200. /***********************************************************************/
  201. {
  202. /*------------------------- external data -----------------------------*/
  203.  extern short prefix_width;
  204.  extern short compatible;
  205. /*--------------------------- local data ------------------------------*/
  206.  unsigned short x=0,y=0;
  207.  short col=0,old_col=0;
  208.  short left_column=0;
  209.  short rc=RC_OK;
  210. /*--------------------------- processing ------------------------------*/
  211. #ifdef TRACE
  212.  trace_function("cursor.c:  cursor_left");
  213. #endif
  214. /*---------------------------------------------------------------------*/
  215. /* The following should be a temporary fix for KEDIT compatability...  */
  216. /*---------------------------------------------------------------------*/
  217.  if (CURRENT_VIEW->prefix
  218.  &&  kedit_defaults)
  219.     escreen = FALSE;
  220.  getyx(CURRENT_WINDOW,y,x);
  221. /*---------------------------------------------------------------------*/
  222. /* If we are in the prefix area and the prefix is on the right and the */
  223. /* current prefix width is not the maximum(PREFIX_WIDTH) then the last */
  224. /* enterable column is column 1.                                       */
  225. /*---------------------------------------------------------------------*/
  226.  if (CURRENT_VIEW->current_window == WINDOW_PREFIX
  227.  &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT
  228.  &&  prefix_width != PREFIX_WIDTH)
  229.     left_column = 1;
  230.  else
  231.     left_column = 0;
  232. /*---------------------------------------------------------------------*/
  233. /* For all windows, if we are not at left column, move 1 pos to left.  */
  234. /*---------------------------------------------------------------------*/
  235.  if (x > left_column)
  236.    {
  237.     wmove(CURRENT_WINDOW,y,x-1);
  238. #ifdef TRACE
  239.     trace_return();
  240. #endif
  241.     return(RC_OK);
  242.    }
  243. /*---------------------------------------------------------------------*/
  244. /* For all windows, determine if CMDARROWSTABLRx is set for tabbing or */
  245. /* scrolling and act accordingly.                                      */
  246. /*---------------------------------------------------------------------*/
  247.  switch(CURRENT_VIEW->current_window)
  248.    {
  249.     case WINDOW_MAIN:
  250.          if (!escreen)
  251.            {
  252.             if (CURRENT_VIEW->prefix)
  253.                rc = Sos_prefix("");
  254.             rc = Sos_lastcol("");
  255.            }
  256.          else
  257.            {
  258. #ifdef VERSHIFT
  259.             if (CURRENT_VIEW->verify_col != 1)
  260.               {
  261.                rc = execute_move_cursor(CURRENT_VIEW->verify_col-2);
  262. #else
  263.             if (CURRENT_VIEW->verify_start != CURRENT_VIEW->verify_col)
  264.               {
  265.                old_col = (CURRENT_VIEW->verify_col-1);
  266.                x = CURRENT_SCREEN.cols[WINDOW_MAIN] / 2;
  267.                col = max((short)CURRENT_VIEW->verify_start,
  268.                          (short)(CURRENT_VIEW->verify_col-1) - (short)x);
  269.                CURRENT_VIEW->verify_col = col;
  270.                build_current_screen();
  271.                display_current_screen();
  272.                x = old_col - (CURRENT_VIEW->verify_col-1);
  273.                wmove(CURRENT_WINDOW,y,x-1);
  274. #endif
  275.  
  276.               }
  277.             else
  278.               {
  279.                extern short compatible;
  280.                if (compatible == COMPAT_KEDIT)
  281.                  {
  282.                   if (CURRENT_VIEW->prefix)
  283.                      if ((CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  284.                         rc = Sos_prefix("");
  285.                   rc = Sos_lastcol("");
  286.                  }
  287.               }
  288.            }
  289.          break;
  290.     case WINDOW_PREFIX:
  291.     case WINDOW_COMMAND:
  292.          if ((escreen
  293.          &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT)
  294.          ||  !escreen)
  295.              rc = Sos_rightedge("");
  296.          break;
  297.     default:
  298.          break;
  299.    }
  300. #ifdef TRACE
  301.  trace_return();
  302. #endif
  303.  return(rc);
  304. }
  305. /***********************************************************************/
  306. #ifdef PROTO
  307. short cursor_right(bool escreen,bool kedit_defaults)
  308. #else
  309. short cursor_right(escreen,kedit_defaults)
  310. bool escreen,kedit_defaults;
  311. #endif
  312. /***********************************************************************/
  313. {
  314. /*------------------------- external data -----------------------------*/
  315.  extern short prefix_width;
  316.  extern short compatible;
  317. /*--------------------------- local data ------------------------------*/
  318.  unsigned short x=0,y=0,tempx=0;
  319.  short right_column=0;
  320.  short rc=RC_OK;
  321. /*--------------------------- processing ------------------------------*/
  322. #ifdef TRACE
  323.  trace_function("cursor.c:  cursor_right");
  324. #endif
  325. /*---------------------------------------------------------------------*/
  326. /* The following should be a temporary fix for KEDIT compatability...  */
  327. /*---------------------------------------------------------------------*/
  328.  if (CURRENT_VIEW->prefix
  329.  &&  kedit_defaults)
  330.     escreen = FALSE;
  331.  getyx(CURRENT_WINDOW,y,x);
  332. /*---------------------------------------------------------------------*/
  333. /* Check for going past end of line - max_line_length                  */
  334. /*---------------------------------------------------------------------*/
  335.  if (CURRENT_VIEW->verify_col+x+1 > max_line_length)
  336.    {
  337. #ifdef TRACE
  338.     trace_return();
  339. #endif
  340.     return(RC_OK);
  341.    }
  342. /*---------------------------------------------------------------------*/
  343. /* If we are in the prefix area and the prefix is on the left and the  */
  344. /* current prefix width is not the maximum(PREFIX_WIDTH) then the last */
  345. /* enterable column is 1 column less.                                  */
  346. /*---------------------------------------------------------------------*/
  347.  if (CURRENT_VIEW->current_window == WINDOW_PREFIX
  348.  &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT
  349.  &&  prefix_width != PREFIX_WIDTH)
  350.     right_column = getmaxx(CURRENT_WINDOW)-2;
  351.  else
  352.     right_column = getmaxx(CURRENT_WINDOW)-1;
  353. /*---------------------------------------------------------------------*/
  354. /* For all windows, if we are not at right column, move 1 pos to right.*/
  355. /*---------------------------------------------------------------------*/
  356.  if (x < right_column)
  357.    {
  358.     wmove(CURRENT_WINDOW,y,x+1);
  359. #ifdef TRACE
  360.     trace_return();
  361. #endif
  362.     return(RC_OK);
  363.    }
  364. /*---------------------------------------------------------------------*/
  365. /* For all windows, determine if CMDARROWSTABLRx is set for tabbing or */
  366. /* scrolling and act accordingly.                                      */
  367. /*---------------------------------------------------------------------*/
  368.  switch(CURRENT_VIEW->current_window)
  369.    {
  370.     case WINDOW_MAIN:
  371.          if (!escreen)
  372.            {
  373.             if (CURRENT_VIEW->prefix)
  374.                rc = Sos_prefix("");
  375.             else
  376.                wmove(CURRENT_WINDOW,y,0); /* this should move down a line too */
  377.            }
  378.          else
  379.            {
  380. #ifdef VERSHIFT
  381.             rc = execute_move_cursor(right_column+1);
  382. #else
  383.             tempx = getmaxx(CURRENT_WINDOW);
  384.             if (x == tempx-1)
  385.               {
  386.                x = (tempx / 2);
  387.                CURRENT_VIEW->verify_col += x;
  388.                build_current_screen();
  389.                display_current_screen();
  390.                wmove(CURRENT_WINDOW,y,x+(tempx % 2));
  391.               }
  392. #endif
  393.  
  394.            }
  395.          break;
  396.     case WINDOW_PREFIX:
  397.     case WINDOW_COMMAND:
  398.          if (!escreen)
  399.             rc = Sos_leftedge("");
  400.          else 
  401.             if ((CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  402.                Tabpre("");
  403.          break;
  404.     default:
  405.          break;
  406.    }
  407. #ifdef TRACE
  408.  trace_return();
  409. #endif
  410.  return(rc);
  411. }
  412. /***********************************************************************/
  413. #ifdef PROTO
  414. short cursor_up(bool escreen)
  415. #else
  416. short cursor_up(escreen)
  417. bool escreen;
  418. #endif
  419. /***********************************************************************/
  420. {
  421. /*------------------------- external data -----------------------------*/
  422.  extern CHARTYPE CMDARROWSTABCMDx;
  423. /*--------------------------- local data ------------------------------*/
  424.  short rc=RC_OK;
  425.  CHARTYPE *current_command=NULL;
  426. /*--------------------------- processing ------------------------------*/
  427. #ifdef TRACE
  428.  trace_function("cursor.c:  cursor_up");
  429. #endif
  430.  switch(CURRENT_VIEW->current_window)
  431.    {
  432.     case WINDOW_MAIN:
  433.     case WINDOW_PREFIX:
  434.          rc = scroll_line(DIRECTION_BACKWARD,1L,FALSE,escreen);
  435.          break;
  436.     case WINDOW_COMMAND:
  437. /*---------------------------------------------------------------------*/
  438. /* Cycle backward through the command list or tab to last line.        */
  439. /*---------------------------------------------------------------------*/
  440.          if (CMDARROWSTABCMDx)
  441.             rc = Sos_bottomedge("");
  442.          else
  443.            {
  444.             current_command = get_next_command(DIRECTION_FORWARD);
  445.             wmove(CURRENT_WINDOW_COMMAND,0,0);
  446.             my_wclrtoeol(CURRENT_WINDOW_COMMAND);
  447.             if (current_command != (CHARTYPE *)NULL)
  448.                Cmsg(current_command);
  449.            }
  450.          break;
  451.     default:
  452.          display_error(2,(CHARTYPE *)"",FALSE);
  453.          rc = RC_INVALID_OPERAND;
  454.          break;
  455.    }
  456. #ifdef TRACE
  457.  trace_return();
  458. #endif
  459.  return(rc);
  460. }
  461. /***********************************************************************/
  462. #ifdef PROTO
  463. short cursor_move(bool escreen,short row,short col)
  464. #else
  465. short cursor_move(escreen,row,col)
  466. bool escreen;
  467. short row,col;
  468. #endif
  469. /***********************************************************************/
  470. {
  471. /*------------------------- external data -----------------------------*/
  472.  extern short prefix_width;
  473. /*--------------------------- local data ------------------------------*/
  474.  register int i=0,j=0;
  475.  short rc=RC_OK;
  476.  unsigned short x=0,y=0;
  477.  unsigned short max_row=0,min_row=0,max_col=0;
  478.  short idx=(-1);
  479. /*--------------------------- processing ------------------------------*/
  480. #ifdef TRACE
  481.  trace_function("cursor.c:  cursor_move");
  482. #endif
  483.  getyx(CURRENT_WINDOW_MAIN,y,x);
  484.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  485.  if (!escreen)
  486.    {
  487.     if (find_last_focus_line(&max_row) != RC_OK)
  488.       {
  489. #ifdef TRACE
  490.        trace_return();
  491. #endif
  492.        return(rc);
  493.       }
  494.     if (find_first_focus_line(&min_row) != RC_OK)
  495.       {
  496. #ifdef TRACE
  497.        trace_return();
  498. #endif
  499.        return(rc);
  500.       }
  501.     if (row == 0)
  502.        row = y;
  503.     else
  504.       {
  505.        if (row > max_row)
  506.           row = max_row;
  507.        else
  508.          {
  509.           if (row < min_row)
  510.              row = min_row;
  511.           else
  512.             {
  513.              if (CURRENT_SCREEN.sl[row-1].main_enterable)
  514.                 row--;
  515.              else
  516.                {
  517.                 display_error(63,"",FALSE);
  518. #ifdef TRACE
  519.                 trace_return();
  520. #endif
  521.                 return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  522.                }
  523.             }
  524.          }
  525.       }
  526.     max_col = CURRENT_SCREEN.cols[WINDOW_MAIN];
  527.     if (col == 0)
  528.        col = x;
  529.     else
  530.        if (col > max_col)
  531.           col = max_col - 1;
  532.        else
  533.           col--;
  534.     switch(CURRENT_VIEW->current_window)
  535.       {
  536.        case WINDOW_COMMAND:
  537.             rc = cursor_home(FALSE);
  538.             break;
  539.        case WINDOW_PREFIX:
  540.             CURRENT_VIEW->current_window = WINDOW_MAIN;
  541.             break;
  542.       }
  543.     wmove(CURRENT_WINDOW_MAIN,row,col);
  544.     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[row].line_number;
  545.     pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  546.    }
  547.  else
  548. /*---------------------------------------------------------------------*/
  549. /* For CURSOR ESCREEN...                                               */
  550. /*---------------------------------------------------------------------*/
  551.    {
  552. /*---------------------------------------------------------------------*/
  553. /* Convert supplied row/col to 0 based offset...                       */
  554. /*---------------------------------------------------------------------*/
  555.     if (row == 0)
  556.        row = CURRENT_SCREEN.start_row[CURRENT_VIEW->current_window] + y;
  557.     else
  558.        row--;
  559.     if (col == 0)
  560.        col = CURRENT_SCREEN.start_col[CURRENT_VIEW->current_window] + x;
  561.     else
  562.        col--;
  563.     max_row = CURRENT_SCREEN.screen_rows - 1;
  564.     max_col = CURRENT_SCREEN.screen_cols - 1;
  565. /*---------------------------------------------------------------------*/
  566. /* If row/col outside maximum screen size, exit...                     */
  567. /*---------------------------------------------------------------------*/
  568.     if (row > max_row
  569.     ||  col > max_col)
  570.       {
  571.        display_error(63,"",FALSE);
  572. #ifdef TRACE
  573.        trace_return();
  574. #endif
  575.        return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  576.       }
  577. /*---------------------------------------------------------------------*/
  578. /* Determine which window the cursor will end up in...                 */
  579. /*---------------------------------------------------------------------*/
  580.     for (i=0;i<VIEW_WINDOWS;i++)
  581.       {
  582.        if (row >= CURRENT_SCREEN.start_row[i]
  583.        &&  row <= (CURRENT_SCREEN.start_row[i] + CURRENT_SCREEN.rows[i] - 1)
  584.        &&  col >= CURRENT_SCREEN.start_col[i]
  585.        &&  col <= (CURRENT_SCREEN.start_col[i] + CURRENT_SCREEN.cols[i] - 1))
  586.          {
  587.           idx = i;
  588.           break;
  589.          }
  590.       }
  591.     row = row - CURRENT_SCREEN.start_row[idx];
  592.     col = col - CURRENT_SCREEN.start_col[idx];
  593.     switch(idx)
  594.       {
  595.        case WINDOW_MAIN:
  596.             row = get_row_for_tof_eof(row,current_screen);
  597.             if (!CURRENT_SCREEN.sl[row].main_enterable)
  598.               {
  599.                display_error(63,"",FALSE);
  600. #ifdef TRACE
  601.                trace_return();
  602. #endif
  603.                return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  604.               }
  605.             rc = Sos_current("");
  606.             wmove(CURRENT_WINDOW_MAIN,row,col);
  607.             CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[row].line_number;
  608.             pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  609.             break;
  610.        case WINDOW_PREFIX:
  611.             row = get_row_for_tof_eof(row,current_screen);
  612.             if (!CURRENT_SCREEN.sl[row].prefix_enterable)
  613.               {
  614.                display_error(63,"",FALSE);
  615. #ifdef TRACE
  616.                trace_return();
  617. #endif
  618.                return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  619.               }
  620.             if ((CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_LEFT
  621.             &&  prefix_width != PREFIX_WIDTH
  622.             &&  col == prefix_width)
  623.               {
  624.                display_error(63,"",FALSE);
  625. #ifdef TRACE
  626.                trace_return();
  627. #endif
  628.                return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  629.               }
  630.             if ((CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT
  631.             &&  prefix_width != PREFIX_WIDTH
  632.             &&  col == 0)
  633.               {
  634.                display_error(63,"",FALSE);
  635. #ifdef TRACE
  636.                trace_return();
  637. #endif
  638.                return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  639.               }
  640.             rc = Sos_current("");
  641.             rc = Sos_prefix("");
  642.             wmove(CURRENT_WINDOW_PREFIX,row,col);
  643.             CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[row].line_number;
  644.             pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  645.             break;
  646.        case WINDOW_COMMAND:
  647.             rc = cursor_cmdline(col+1);
  648.             break;
  649.        default:
  650.             display_error(63,"",FALSE);
  651. #ifdef TRACE
  652.             trace_return();
  653. #endif
  654.             return(RC_TOF_EOF_REACHED);/* this is a strange RC :-( */
  655.             break;
  656.       }
  657.    }
  658. #ifdef TRACE
  659.  trace_return();
  660. #endif
  661.  return(rc);
  662. }
  663. /***********************************************************************/
  664. #ifdef PROTO
  665. long where_now(void)
  666. #else
  667. long where_now()
  668. #endif
  669. /***********************************************************************/
  670. {
  671. /*------------------------- external data -----------------------------*/
  672.  extern CHARTYPE display_screens;
  673. /*--------------------------- local data ------------------------------*/
  674.  long rc=0L;
  675.  unsigned short x=0,y=0;
  676. /*--------------------------- processing ------------------------------*/
  677. #ifdef TRACE
  678.  trace_function("cursor.c:  where_now");
  679. #endif
  680.  getyx(CURRENT_WINDOW,y,x);
  681.  switch(CURRENT_VIEW->current_window)
  682.    {
  683.     case WINDOW_MAIN:
  684.          rc |= WHERE_WINDOW_MAIN;
  685.          break;
  686.     case WINDOW_PREFIX:
  687.          if ((CURRENT_VIEW->prefix & PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  688.             rc |= WHERE_WINDOW_PREFIX_LEFT;
  689.          else
  690.             rc |= WHERE_WINDOW_PREFIX_RIGHT;
  691.          break;
  692.     case WINDOW_COMMAND:
  693.          if (CURRENT_VIEW->cmd_line == 'B')
  694.             rc |= WHERE_WINDOW_CMDLINE_BOTTOM;
  695.          else
  696.             rc |= WHERE_WINDOW_CMDLINE_TOP;
  697.          break;
  698.    }
  699.  if (display_screens == 1)
  700.     rc |= WHERE_SCREEN_ONLY;
  701.  else
  702.    {
  703.     if (current_screen == 0)
  704.        rc |= WHERE_SCREEN_FIRST;
  705.     else
  706.        rc |= WHERE_SCREEN_LAST;
  707.    }
  708.  rc |= (long)y;
  709. #ifdef TRACE
  710.  trace_return();
  711. #endif
  712.  return(rc);
  713. }
  714. /***********************************************************************/
  715. #ifdef PROTO
  716. long what_current_now(void)
  717. #else
  718. long what_current_now()
  719. #endif
  720. /***********************************************************************/
  721. {
  722. /*------------------------- external data -----------------------------*/
  723. /*--------------------------- local data ------------------------------*/
  724.  long rc=0;
  725. /*--------------------------- processing ------------------------------*/
  726. #ifdef TRACE
  727.  trace_function("cursor.c:  what_current_now");
  728. #endif
  729.  if (CURRENT_WINDOW_PREFIX != NULL)
  730.    {
  731.     if ((CURRENT_VIEW->prefix & PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  732.        rc |= WHERE_WINDOW_PREFIX_LEFT;
  733.     else
  734.        rc |= WHERE_WINDOW_PREFIX_RIGHT;
  735.    }
  736.  if (CURRENT_VIEW->cmd_line == 'B')
  737.     rc |= WHERE_WINDOW_CMDLINE_BOTTOM;
  738.  else
  739.     if (CURRENT_VIEW->cmd_line == 'T')
  740.        rc |= WHERE_WINDOW_CMDLINE_TOP;
  741. #ifdef TRACE
  742.  trace_return();
  743. #endif
  744.  return(rc);
  745. }
  746. /***********************************************************************/
  747. #ifdef PROTO
  748. long what_other_now(void)
  749. #else
  750. long what_other_now()
  751. #endif
  752. /***********************************************************************/
  753. {
  754. /*------------------------- external data -----------------------------*/
  755.  extern CHARTYPE display_screens;
  756. /*--------------------------- local data ------------------------------*/
  757.  long rc=0L;
  758. /*--------------------------- processing ------------------------------*/
  759. #ifdef TRACE
  760.  trace_function("cursor.c:  what_other_now");
  761. #endif
  762. if (display_screens == 1)
  763.   {
  764. #ifdef TRACE
  765.    trace_return();
  766. #endif
  767.    return(rc);
  768.   }
  769.  if (OTHER_SCREEN.win[WINDOW_PREFIX] != NULL)
  770.    {
  771.     if ((OTHER_SCREEN.screen_view->prefix & PREFIX_LOCATION_MASK) == PREFIX_LEFT)
  772.        rc |= WHERE_WINDOW_PREFIX_LEFT;
  773.     else
  774.        rc |= WHERE_WINDOW_PREFIX_RIGHT;
  775.    }
  776.  if (OTHER_SCREEN.screen_view->cmd_line == 'B')
  777.     rc |= WHERE_WINDOW_CMDLINE_BOTTOM;
  778.  else
  779.     if (OTHER_SCREEN.screen_view->cmd_line == 'T')
  780.        rc |= WHERE_WINDOW_CMDLINE_TOP;
  781. #ifdef TRACE
  782.  trace_return();
  783. #endif
  784.  return(rc);
  785. }
  786. /***********************************************************************/
  787. #ifdef PROTO
  788. long where_next(long where,long what_current,long what_other)
  789. #else
  790. long where_next(where,what_current,what_other)
  791. long where,what_current,what_other;
  792. #endif
  793. /***********************************************************************/
  794. {
  795. /*------------------------- external data -----------------------------*/
  796. /*--------------------------- local data ------------------------------*/
  797.  long where_row=0L,where_window=0L,where_screen=0L;
  798.  long what_current_window=0L;
  799.  long what_other_window=0L,what_other_screen=0L;
  800.  long rc=0L;
  801.  unsigned short current_top_row=0,current_bottom_row=0;
  802. /*--------------------------- processing ------------------------------*/
  803.  where_row = where & WHERE_ROW_MASK;
  804.  where_window = where & WHERE_WINDOW_MASK;
  805.  where_screen = where & WHERE_SCREEN_MASK;
  806.  what_current_window = what_current & WHERE_WINDOW_MASK;
  807.  what_other_window = what_other & WHERE_WINDOW_MASK;
  808.  find_first_focus_line(¤t_top_row);
  809.  find_last_focus_line(¤t_bottom_row);
  810.  
  811.  switch(where_window)
  812.    {
  813.     case WHERE_WINDOW_MAIN:
  814. /*---------------------------------------------------------------------*/
  815. /* In filearea.                                                        */
  816. /*---------------------------------------------------------------------*/
  817.          if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  818. /*---------------------------------------------------------------------*/
  819. /* In filearea and there is prefix on right.                           */
  820. /* Result: same row,same screen,go to prefix.                          */
  821. /*---------------------------------------------------------------------*/
  822.             return(where_row | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  823.          switch(where_screen)
  824.            {
  825.             case WHERE_SCREEN_FIRST:
  826.             case WHERE_SCREEN_LAST:
  827.                      /* the two cases above will be separate in future */
  828.             case WHERE_SCREEN_ONLY:
  829. /*---------------------------------------------------------------------*/
  830. /* In filearea and only screen.                                        */
  831. /*---------------------------------------------------------------------*/
  832.                  if (where_row == (long)current_bottom_row)
  833.                    {
  834. /*---------------------------------------------------------------------*/
  835. /* In filearea, prefix on left or off, on bottom line.                 */
  836. /*---------------------------------------------------------------------*/
  837.                     if (what_current_window & WHERE_WINDOW_CMDLINE_TOP)
  838. /*---------------------------------------------------------------------*/
  839. /* In filearea,prefix on left or off, on bottom line.                  */
  840. /* Result: row irrelevant,same screen,go to cmdline.                   */
  841. /*---------------------------------------------------------------------*/
  842.                        return(where_row | where_screen | WHERE_WINDOW_CMDLINE_TOP);
  843.                     if (what_current_window & WHERE_WINDOW_CMDLINE_BOTTOM)
  844. /*---------------------------------------------------------------------*/
  845. /* In filearea,prefix on left or off, on bottom line.                  */
  846. /* Result: row irrelevant,same screen,go to cmdline.                   */
  847. /*---------------------------------------------------------------------*/
  848.                        return(where_row | where_screen | WHERE_WINDOW_CMDLINE_BOTTOM);
  849. /*---------------------------------------------------------------------*/
  850. /******************* To get here, there is no cmdline. *****************/
  851. /*---------------------------------------------------------------------*/
  852.                     if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  853. /*---------------------------------------------------------------------*/
  854. /* In filearea,prefix on left or off, on bottom line.                  */
  855. /* Result: first row,same screen,go to prefix.                         */
  856. /*---------------------------------------------------------------------*/
  857.                        return((long)current_top_row | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  858.                    }
  859. /*---------------------------------------------------------------------*/
  860. /******************* To get here, we are not on last row. **************/
  861. /*---------------------------------------------------------------------*/
  862.                  if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  863. /*---------------------------------------------------------------------*/
  864. /* In filearea, prefix on left, not on bottom line.                    */
  865. /* Result: next row,same screen,go to prefix.                          */
  866. /*---------------------------------------------------------------------*/
  867.                     return(where_row+1L | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  868. /*---------------------------------------------------------------------*/
  869. /* In filearea, no prefix, not on bottom line.                         */
  870. /* Result: next row,same screen,same window.                           */
  871. /*---------------------------------------------------------------------*/
  872.                  return(where_row+1L | where_screen | WHERE_WINDOW_MAIN);
  873.                  break;
  874.            }
  875.          break;
  876.     case WHERE_WINDOW_PREFIX_LEFT:
  877.          rc = where_row | where_screen | WHERE_WINDOW_MAIN;
  878.          break;
  879.     case WHERE_WINDOW_PREFIX_RIGHT:
  880.          switch(where_screen)
  881.            {
  882.             case WHERE_SCREEN_FIRST:
  883.             case WHERE_SCREEN_LAST:
  884.                      /* the two cases above will be separate in future */
  885.             case WHERE_SCREEN_ONLY:
  886. /*---------------------------------------------------------------------*/
  887. /* In right prefix and only screen.                                    */
  888. /*---------------------------------------------------------------------*/
  889.                  if (where_row != (long)current_bottom_row)
  890. /*---------------------------------------------------------------------*/
  891. /* In right prefix and not on bottom line.                             */
  892. /* Result: next row,same screen,go to filearea.                        */
  893. /*---------------------------------------------------------------------*/
  894.                     return(where_row+1L | where_screen | WHERE_WINDOW_MAIN);
  895.                  if (what_current_window & WHERE_WINDOW_CMDLINE_BOTTOM)
  896. /*---------------------------------------------------------------------*/
  897. /* In right prefix, cmdline on bottom, on bottom line.                 */
  898. /* Result: row irrelevant,same screen,go to cmdline.                   */
  899. /*---------------------------------------------------------------------*/
  900.                     return(where_row | where_screen | WHERE_WINDOW_CMDLINE_BOTTOM);
  901.                  if (what_current_window & WHERE_WINDOW_CMDLINE_TOP)
  902. /*---------------------------------------------------------------------*/
  903. /* In right prefix, cmdline on top, on bottom line.                    */
  904. /* Result: row irrelevant,same screen,go to cmdline.                   */
  905. /*---------------------------------------------------------------------*/
  906.                     return(where_row | where_screen | WHERE_WINDOW_CMDLINE_TOP);
  907. /*---------------------------------------------------------------------*/
  908. /* In right prefix, no cmdline, on bottom line.                        */
  909. /* Result: first row,same screen,go to filearea.                       */
  910. /*---------------------------------------------------------------------*/
  911.                  return((long)current_top_row | where_screen | WHERE_WINDOW_MAIN);
  912.                  break;
  913.            }
  914.          break;
  915.     case WHERE_WINDOW_CMDLINE_TOP:
  916.          switch(where_screen)
  917.            {
  918.             case WHERE_SCREEN_FIRST:
  919.             case WHERE_SCREEN_LAST:
  920.                      /* the two cases above will be separate in future */
  921.             case WHERE_SCREEN_ONLY:
  922. /*---------------------------------------------------------------------*/
  923. /* In cmdline, and only screen.                                        */
  924. /*---------------------------------------------------------------------*/
  925.                  if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  926. /*---------------------------------------------------------------------*/
  927. /* In cmdline, and only screen and prefix on left.                     */
  928. /* Result: first row, same screen, go to prefix.                       */
  929. /*---------------------------------------------------------------------*/
  930.                     return((long)current_top_row | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  931. /*---------------------------------------------------------------------*/
  932. /* In cmdline, and prefix on right or none.                            */
  933. /* Result: first row, same screen, go to filearea.                     */
  934. /*---------------------------------------------------------------------*/
  935.                  return((long)current_top_row | where_screen | WHERE_WINDOW_MAIN);
  936.                  break;
  937.            }
  938.          break;
  939.     case WHERE_WINDOW_CMDLINE_BOTTOM:
  940.          switch(where_screen)
  941.            {
  942.             case WHERE_SCREEN_FIRST:
  943.             case WHERE_SCREEN_LAST:
  944.                      /* the two cases above will be separate in future */
  945.             case WHERE_SCREEN_ONLY:
  946. /*---------------------------------------------------------------------*/
  947. /* In cmdline, and only screen.                                        */
  948. /*---------------------------------------------------------------------*/
  949.                  if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  950. /*---------------------------------------------------------------------*/
  951. /* In cmdline, and only screen and prefix on left.                     */
  952. /* Result: first row, same screen, go to prefix.                       */
  953. /*---------------------------------------------------------------------*/
  954.                     return((long)current_top_row | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  955. /*---------------------------------------------------------------------*/
  956. /* In cmdline, and prefix on right or none.                            */
  957. /* Result: first row, same screen, go to filearea.                     */
  958. /*---------------------------------------------------------------------*/
  959.                  return((long)current_top_row | where_screen | WHERE_WINDOW_MAIN);
  960.                  break;
  961.            }
  962.          break;
  963.    }
  964.  return(rc);
  965. }
  966. /***********************************************************************/
  967. #ifdef PROTO
  968. long where_before(long where,long what_current,long what_other)
  969. #else
  970. long where_before(where,what_current,what_other)
  971. long where,what_current,what_other;
  972. #endif
  973. /***********************************************************************/
  974. {
  975. /*------------------------- external data -----------------------------*/
  976. /*--------------------------- local data ------------------------------*/
  977.  long where_row=0L,where_window=0L,where_screen=0L;
  978.  long what_current_window=0L;
  979.  long what_other_window=0L,what_other_screen=0L;
  980.  long rc=0L;
  981.  unsigned short current_top_row=0,current_bottom_row=0;
  982. /*--------------------------- processing ------------------------------*/
  983.  where_row = where & WHERE_ROW_MASK;
  984.  where_window = where & WHERE_WINDOW_MASK;
  985.  where_screen = where & WHERE_SCREEN_MASK;
  986.  what_current_window = what_current & WHERE_WINDOW_MASK;
  987.  what_other_window = what_other & WHERE_WINDOW_MASK;
  988.  find_first_focus_line(¤t_top_row);
  989.  find_last_focus_line(¤t_bottom_row);
  990.  
  991.  switch(where_window)
  992.    {
  993.     case WHERE_WINDOW_MAIN:
  994. /*---------------------------------------------------------------------*/
  995. /* In filearea.                                                        */
  996. /*---------------------------------------------------------------------*/
  997.          if (what_current_window & WHERE_WINDOW_PREFIX_LEFT)
  998. /*---------------------------------------------------------------------*/
  999. /* In filearea and there is prefix on left.                            */
  1000. /* Result: same row,same screen,go to prefix.                          */
  1001. /*---------------------------------------------------------------------*/
  1002.             return(where_row | where_screen | WHERE_WINDOW_PREFIX_LEFT);
  1003.          switch(where_screen)
  1004.            {
  1005.             case WHERE_SCREEN_FIRST:
  1006.             case WHERE_SCREEN_LAST:
  1007.                      /* the two cases above will be separate in future */
  1008.             case WHERE_SCREEN_ONLY:
  1009. /*---------------------------------------------------------------------*/
  1010. /* In filearea and only screen.                                        */
  1011. /*---------------------------------------------------------------------*/
  1012.                  if (where_row == (long)current_top_row)
  1013.                    {
  1014. /*---------------------------------------------------------------------*/
  1015. /* In filearea, prefix on right or off, on top    line.                */
  1016. /*---------------------------------------------------------------------*/
  1017.                     if (what_current_window & WHERE_WINDOW_CMDLINE_BOTTOM)
  1018. /*---------------------------------------------------------------------*/
  1019. /* In filearea,prefix on right or off, on top    line.                 */
  1020. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1021. /*---------------------------------------------------------------------*/
  1022.                        return(where_row | where_screen | WHERE_WINDOW_CMDLINE_BOTTOM);
  1023.                     if (what_current_window & WHERE_WINDOW_CMDLINE_TOP)
  1024. /*---------------------------------------------------------------------*/
  1025. /* In filearea,prefix on right or off, on top    line.                 */
  1026. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1027. /*---------------------------------------------------------------------*/
  1028.                        return(where_row | where_screen | WHERE_WINDOW_CMDLINE_TOP);
  1029. /*---------------------------------------------------------------------*/
  1030. /******************* To get here, there is no cmdline. *****************/
  1031. /*---------------------------------------------------------------------*/
  1032.                     if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  1033. /*---------------------------------------------------------------------*/
  1034. /* In filearea,prefix on right or off, on top    line.                 */
  1035. /* Result: last  row,same screen,go to prefix.                         */
  1036. /*---------------------------------------------------------------------*/
  1037.                        return((long)current_bottom_row | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1038.                    }
  1039. /*---------------------------------------------------------------------*/
  1040. /******************* To get here, we are not on top  row. **************/
  1041. /*---------------------------------------------------------------------*/
  1042.                  if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  1043. /*---------------------------------------------------------------------*/
  1044. /* In filearea, prefix on right, not on top    line.                   */
  1045. /* Result: prior row,same screen,go to prefix.                         */
  1046. /*---------------------------------------------------------------------*/
  1047.                     return(where_row-1L | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1048. /*---------------------------------------------------------------------*/
  1049. /* In filearea, no prefix, not on top    line.                         */
  1050. /* Result: prior row,same screen,same window.                          */
  1051. /*---------------------------------------------------------------------*/
  1052.                  return(where_row-1L | where_screen | WHERE_WINDOW_MAIN);
  1053.                  break;
  1054.            }
  1055.          break;
  1056.     case WHERE_WINDOW_PREFIX_RIGHT:
  1057.          rc = where_row | where_screen | WHERE_WINDOW_MAIN;
  1058.          break;
  1059.     case WHERE_WINDOW_PREFIX_LEFT:
  1060.          switch(where_screen)
  1061.            {
  1062.             case WHERE_SCREEN_FIRST:
  1063.             case WHERE_SCREEN_LAST:
  1064.                      /* the two cases above will be separate in future */
  1065.             case WHERE_SCREEN_ONLY:
  1066. /*---------------------------------------------------------------------*/
  1067. /* In left  prefix and only screen.                                    */
  1068. /*---------------------------------------------------------------------*/
  1069.                  if (where_row != (long)current_top_row)
  1070. /*---------------------------------------------------------------------*/
  1071. /* In left  prefix and not on top    line.                             */
  1072. /* Result: prior row,same screen,go to filearea.                       */
  1073. /*---------------------------------------------------------------------*/
  1074.                     return(where_row-1L | where_screen | WHERE_WINDOW_MAIN);
  1075.                  if (what_current_window & WHERE_WINDOW_CMDLINE_BOTTOM)
  1076. /*---------------------------------------------------------------------*/
  1077. /* In left  prefix, cmdline on bottom, on top    line.                 */
  1078. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1079. /*---------------------------------------------------------------------*/
  1080.                     return(where_row | where_screen | WHERE_WINDOW_CMDLINE_BOTTOM);
  1081.                  if (what_current_window & WHERE_WINDOW_CMDLINE_TOP)
  1082. /*---------------------------------------------------------------------*/
  1083. /* In left  prefix, cmdline on top, on top    line.                    */
  1084. /* Result: row irrelevant,same screen,go to cmdline.                   */
  1085. /*---------------------------------------------------------------------*/
  1086.                     return(where_row | where_screen | WHERE_WINDOW_CMDLINE_TOP);
  1087. /*---------------------------------------------------------------------*/
  1088. /* In left  prefix, no cmdline, on top    line.                        */
  1089. /* Result: last  row,same screen,go to filearea.                       */
  1090. /*---------------------------------------------------------------------*/
  1091.                  return((long)current_bottom_row | where_screen | WHERE_WINDOW_MAIN);
  1092.                  break;
  1093.            }
  1094.          break;
  1095.     case WHERE_WINDOW_CMDLINE_TOP:
  1096.          switch(where_screen)
  1097.            {
  1098.             case WHERE_SCREEN_FIRST:
  1099.             case WHERE_SCREEN_LAST:
  1100.                      /* the two cases above will be separate in future */
  1101.             case WHERE_SCREEN_ONLY:
  1102. /*---------------------------------------------------------------------*/
  1103. /* In cmdline, and only screen.                                        */
  1104. /*---------------------------------------------------------------------*/
  1105.                  if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  1106. /*---------------------------------------------------------------------*/
  1107. /* In cmdline, and only screen and prefix on right.                    */
  1108. /* Result: last  row, same screen, go to prefix.                       */
  1109. /*---------------------------------------------------------------------*/
  1110.                     return((long)current_bottom_row | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1111. /*---------------------------------------------------------------------*/
  1112. /* In cmdline, and prefix on left  or none.                            */
  1113. /* Result: last  row, same screen, go to filearea.                     */
  1114. /*---------------------------------------------------------------------*/
  1115.                  return((long)current_bottom_row | where_screen | WHERE_WINDOW_MAIN);
  1116.                  break;
  1117.            }
  1118.          break;
  1119.     case WHERE_WINDOW_CMDLINE_BOTTOM:
  1120.          switch(where_screen)
  1121.            {
  1122.             case WHERE_SCREEN_FIRST:
  1123.             case WHERE_SCREEN_LAST:
  1124.                      /* the two cases above will be separate in future */
  1125.             case WHERE_SCREEN_ONLY:
  1126. /*---------------------------------------------------------------------*/
  1127. /* In cmdline, and only screen.                                        */
  1128. /*---------------------------------------------------------------------*/
  1129.                  if (what_current_window & WHERE_WINDOW_PREFIX_RIGHT)
  1130. /*---------------------------------------------------------------------*/
  1131. /* In cmdline, and only screen and prefix on right.                    */
  1132. /* Result: last  row, same screen, go to prefix.                       */
  1133. /*---------------------------------------------------------------------*/
  1134.                     return((long)current_bottom_row | where_screen | WHERE_WINDOW_PREFIX_RIGHT);
  1135. /*---------------------------------------------------------------------*/
  1136. /* In cmdline, and prefix on left  or none.                            */
  1137. /* Result: last  row, same screen, go to filearea.                     */
  1138. /*---------------------------------------------------------------------*/
  1139.                  return((long)current_bottom_row | where_screen | WHERE_WINDOW_MAIN);
  1140.                  break;
  1141.            }
  1142.          break;
  1143.    }
  1144.  return(rc);
  1145. }
  1146. /***********************************************************************/
  1147. #ifdef PROTO
  1148. bool enterable_field(long where)
  1149. #else
  1150. bool enterable_field(where)
  1151. long where;
  1152. #endif
  1153. /***********************************************************************/
  1154. {
  1155. /*------------------------- external data -----------------------------*/
  1156. /*--------------------------- local data ------------------------------*/
  1157.  bool rc=TRUE;
  1158.  ROWTYPE row=0;
  1159.  long where_screen=0L;
  1160.  CHARTYPE scrn=0;
  1161. /*--------------------------- processing ------------------------------*/
  1162. #ifdef TRACE
  1163.  trace_function("cursor.c:  enterable_field");
  1164. #endif
  1165.  where_screen = where & WHERE_SCREEN_MASK;
  1166.  row = (ROWTYPE)(where & WHERE_ROW_MASK);
  1167.  scrn = (where_screen == WHERE_SCREEN_LAST) ? 1 : 0;
  1168.  switch(where & WHERE_WINDOW_MASK)
  1169.    {
  1170.     case WHERE_WINDOW_MAIN:
  1171.          if (!screen[scrn].sl[row].main_enterable)
  1172.             rc = FALSE;
  1173.          break;
  1174.     case WHERE_WINDOW_PREFIX_LEFT:
  1175.     case WHERE_WINDOW_PREFIX_RIGHT:
  1176.          if (!screen[scrn].sl[row].prefix_enterable)
  1177.             rc = FALSE;
  1178.          break;
  1179.     case WHERE_WINDOW_CMDLINE_TOP:
  1180.     case WHERE_WINDOW_CMDLINE_BOTTOM:
  1181.          break;
  1182.    }
  1183. #ifdef TRACE
  1184.  trace_return();
  1185. #endif
  1186.  return(rc);
  1187. }
  1188. /***********************************************************************/
  1189. #ifdef PROTO
  1190. short go_to_new_field(long save_where,long where)
  1191. #else
  1192. short go_to_new_field(save_where,where)
  1193. long save_where,where;
  1194. #endif
  1195. /***********************************************************************/
  1196. {
  1197. /*------------------------- external data -----------------------------*/
  1198.  extern short prefix_width;
  1199. /*--------------------------- local data ------------------------------*/
  1200.  short rc=RC_OK;
  1201.  long save_where_screen=0L,where_screen=0L;
  1202.  long save_where_window=0L,where_window=0L;
  1203.  unsigned short x=0;
  1204.  ROWTYPE where_row=0;
  1205. /*--------------------------- processing ------------------------------*/
  1206. #ifdef TRACE
  1207.  trace_function("cursor.c:  go_to_new_field");
  1208. #endif
  1209.  save_where_screen = save_where & WHERE_SCREEN_MASK;
  1210.  where_screen = where & WHERE_SCREEN_MASK;
  1211.  save_where_window = save_where & WHERE_WINDOW_MASK;
  1212.  where_window = where & WHERE_WINDOW_MASK;
  1213.  where_row = (ROWTYPE)(where & WHERE_ROW_MASK);
  1214.  if (save_where_screen != where_screen)
  1215.    {
  1216.    }
  1217.  if (save_where_window == where_window)
  1218. /*---------------------------------------------------------------------*/
  1219. /* No change to screen or window...                                    */
  1220. /*---------------------------------------------------------------------*/
  1221.     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1222.  else
  1223.    {
  1224.     switch(save_where_window)
  1225.       {
  1226.        case WHERE_WINDOW_MAIN:
  1227.             switch(where_window)
  1228.               {
  1229.                case WHERE_WINDOW_PREFIX_LEFT:
  1230.                case WHERE_WINDOW_PREFIX_RIGHT:
  1231.                     CURRENT_VIEW->current_window = WINDOW_PREFIX;
  1232.                     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1233.                     break;
  1234.                case WHERE_WINDOW_CMDLINE_TOP:
  1235.                case WHERE_WINDOW_CMDLINE_BOTTOM:
  1236.                     CURRENT_VIEW->previous_window = CURRENT_VIEW->current_window;
  1237.                     CURRENT_VIEW->current_window = WINDOW_COMMAND;
  1238.                     where_row = 0;
  1239.                     break;
  1240.               }
  1241.             break;
  1242.        case WHERE_WINDOW_PREFIX_LEFT:
  1243.        case WHERE_WINDOW_PREFIX_RIGHT:
  1244.             switch(where_window)
  1245.               {
  1246.                case WHERE_WINDOW_MAIN:
  1247.                     CURRENT_VIEW->current_window = WINDOW_MAIN;
  1248.                     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1249.                     break;
  1250.                case WHERE_WINDOW_CMDLINE_TOP:
  1251.                case WHERE_WINDOW_CMDLINE_BOTTOM:
  1252.                     CURRENT_VIEW->previous_window = CURRENT_VIEW->current_window;
  1253.                     CURRENT_VIEW->current_window = WINDOW_COMMAND;
  1254.                     where_row = 0;
  1255.                     break;
  1256.               }
  1257.             break;
  1258.        case WHERE_WINDOW_CMDLINE_TOP:
  1259.        case WHERE_WINDOW_CMDLINE_BOTTOM:
  1260.             switch(where_window)
  1261.               {
  1262.                case WHERE_WINDOW_PREFIX_LEFT:
  1263.                case WHERE_WINDOW_PREFIX_RIGHT:
  1264.                     CURRENT_VIEW->current_window = WINDOW_PREFIX;
  1265.                     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1266.                     break;
  1267.                case WHERE_WINDOW_MAIN:
  1268.                     CURRENT_VIEW->current_window = WINDOW_MAIN;
  1269.                     CURRENT_VIEW->focus_line = CURRENT_SCREEN.sl[where_row].line_number;
  1270.                     break;
  1271.               }
  1272.             break;
  1273.       }
  1274.    }
  1275.  if (CURRENT_VIEW->current_window == WINDOW_PREFIX
  1276.  &&  (CURRENT_VIEW->prefix&PREFIX_LOCATION_MASK) == PREFIX_RIGHT
  1277.  &&  prefix_width != PREFIX_WIDTH)
  1278.     x = 1;
  1279.  else
  1280.     x = 0;
  1281.  wmove(CURRENT_WINDOW,where_row,x);
  1282. #ifdef TRACE
  1283.  trace_return();
  1284. #endif
  1285.  return(rc);
  1286. }
  1287. /***********************************************************************/
  1288. #ifdef PROTO
  1289. void get_cursor_position(LINETYPE *screen_line,LINETYPE *screen_column,LINETYPE *file_line,LINETYPE *file_column)
  1290. #else
  1291. void get_cursor_position(screen_line,screen_column,file_line,file_column)
  1292. LINETYPE *screen_line,*screen_column,*file_line,*file_column;
  1293. #endif
  1294. /***********************************************************************/
  1295. {
  1296. /*------------------------- external data -----------------------------*/
  1297.  extern bool curses_started;
  1298. /*--------------------------- local data ------------------------------*/
  1299.  unsigned short y=0,x=0;
  1300.  unsigned short begy=0,begx=0;
  1301. /*--------------------------- processing ------------------------------*/
  1302. #ifdef TRACE
  1303.  trace_function("cursor.c:  get_cursor_position");
  1304. #endif
  1305.  if (curses_started)
  1306.    {
  1307.     getyx(CURRENT_WINDOW,y,x);
  1308.     getbegyx(CURRENT_WINDOW,begy,begx);
  1309.     *screen_line = (LINETYPE)(y + begy + 1L);
  1310.     *screen_column = (LINETYPE)(x + begx + 1L);
  1311.    }
  1312.  else
  1313.     *screen_line = *screen_column = (-1L);
  1314.  if (CURRENT_VIEW->current_window != WINDOW_MAIN)
  1315.     *file_line = *file_column = (-1L);
  1316.  else
  1317.    {
  1318.     *file_line = CURRENT_VIEW->focus_line;
  1319.     *file_column = (LINETYPE)x + (LINETYPE)CURRENT_VIEW->verify_start
  1320.                                + (LINETYPE)CURRENT_VIEW->verify_col - 1L;
  1321.    }
  1322. #ifdef TRACE
  1323.  trace_return();
  1324. #endif
  1325.  return;
  1326. }
  1327. /***********************************************************************/
  1328. #ifdef PROTO
  1329. short advance_focus_line(LINETYPE num_lines)
  1330. #else
  1331. short advance_focus_line(num_lines)
  1332. LINETYPE num_lines;
  1333. #endif
  1334. /***********************************************************************/
  1335. {
  1336. /*------------------------- external data -----------------------------*/
  1337.  extern bool curses_started;
  1338. /*--------------------------- local data ------------------------------*/
  1339.  unsigned short y=0,x=0;
  1340.  LINE *curr=NULL;
  1341.  LINETYPE actual_lines=num_lines;
  1342.  short direction=DIRECTION_FORWARD;
  1343. /*--------------------------- processing ------------------------------*/
  1344. #ifdef TRACE
  1345.  trace_function("cursor.c:  advance_focus_line");
  1346. #endif
  1347.  if (num_lines < 0L)
  1348.    {
  1349.     actual_lines = -num_lines;
  1350.     direction = DIRECTION_BACKWARD;
  1351.    }
  1352.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1353.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_VIEW->focus_line);
  1354.  while(actual_lines>0)
  1355.     {
  1356.      if (direction == DIRECTION_BACKWARD)
  1357.         curr = curr->prev;
  1358.      else
  1359.         curr = curr->next;
  1360.      if (curr == NULL)
  1361.         break;
  1362.      CURRENT_VIEW->focus_line += (LINETYPE)direction;
  1363.      if (in_scope(curr) 
  1364.      || CURRENT_VIEW->scope_all)
  1365.         actual_lines--;
  1366.     }
  1367.  if (!line_in_view(CURRENT_VIEW->focus_line))
  1368.     CURRENT_VIEW->current_line = CURRENT_VIEW->focus_line;
  1369.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1370.  build_current_screen();
  1371.  display_current_screen();
  1372.  if (curses_started)
  1373.    {
  1374.     getyx(CURRENT_WINDOW,y,x);
  1375.     y = get_row_for_focus_line(CURRENT_VIEW->focus_line,
  1376.                                CURRENT_VIEW->current_row);
  1377.     wmove(CURRENT_WINDOW,y,x);
  1378.    }
  1379. #ifdef TRACE
  1380.  trace_return();
  1381. #endif
  1382.  if (CURRENT_TOF || CURRENT_BOF)
  1383.     return(RC_TOF_EOF_REACHED);
  1384.  else
  1385.     return(RC_OK);
  1386. }
  1387. /***********************************************************************/
  1388. #ifdef PROTO
  1389. short advance_current_line(LINETYPE num_lines)
  1390. #else
  1391. short advance_current_line(num_lines)
  1392. LINETYPE num_lines;
  1393. #endif
  1394. /***********************************************************************/
  1395. {
  1396. /*------------------------- external data -----------------------------*/
  1397.  extern bool curses_started;
  1398. /*--------------------------- local data ------------------------------*/
  1399.  LINE *curr=NULL;
  1400.  LINETYPE actual_lines=num_lines;
  1401.  short direction=DIRECTION_FORWARD;
  1402. /*--------------------------- processing ------------------------------*/
  1403. #ifdef TRACE
  1404.  trace_function("cursor.c:  advance_current_line");
  1405. #endif
  1406.  if (num_lines < 0L)
  1407.    {
  1408.     actual_lines = -num_lines;
  1409.     direction = DIRECTION_BACKWARD;
  1410.    }
  1411.  post_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1412.  curr = lll_find(CURRENT_FILE->first_line,CURRENT_VIEW->current_line);
  1413.  while(actual_lines>0)
  1414.     {
  1415.      if (direction == DIRECTION_BACKWARD)
  1416.         curr = curr->prev;
  1417.      else
  1418.         curr = curr->next;
  1419.      if (curr == NULL)
  1420.         break;
  1421.      CURRENT_VIEW->current_line += (LINETYPE)direction;
  1422.      if (in_scope(curr) 
  1423.      || CURRENT_VIEW->scope_all)
  1424.         actual_lines--;
  1425.     }
  1426.  build_current_screen();
  1427.  if (!line_in_view(CURRENT_VIEW->focus_line))
  1428.     CURRENT_VIEW->focus_line = CURRENT_VIEW->current_line;
  1429.  pre_process_line(CURRENT_VIEW,CURRENT_VIEW->focus_line);
  1430.  build_current_screen();
  1431.  display_current_screen();
  1432. #ifdef TRACE
  1433.  trace_return();
  1434. #endif
  1435.  if (CURRENT_TOF || CURRENT_BOF)
  1436.     return(RC_TOF_EOF_REACHED);
  1437.  else
  1438.     return(RC_OK);
  1439. }
  1440.